/*
 * @Author: wang cong wangc9832@163.com
 * @Date: 2024-01-23 10:45:50
 * @LastEditors: wang cong wangc9832@163.com
 * @LastEditTime: 2024-05-28 12:04:21
 * @FilePath: /ams_kt_front/src/api/sys/upload.ts
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
import { UploadApiResult } from './model/uploadModel';
import { defHttp } from '@/utils/http/axios';
import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '@/hooks/setting';
import setting from '@/settings/projectSetting';

const { uploadUrl = '' } = useGlobSetting();

export const breakpointUpload = (file?: any) => {
  return defHttp.post({
    url: '/file/breakpointUpload',
    headers: { 'content-type': 'multipart/form-data' },
    params: { ...file },
    // timeout: 1000 * 60 * 100,
    timeout: -1,
  });
};

export const add = (params: any) => {
  return defHttp.post({
    url: '/file/add',
    params,
  });
};
export const del = (id: string) => {
  return defHttp.post({
    url: `/file/delete/${id}`,
  });
};
export const download = (id: string) => {
  window.location.href = `${setting.fileUrl}/download/${id}`;
};
export const list = (groupId: string) => {
  return defHttp.get({ url: '/file/list', params: { groupId } });
};
export const checkFile = (md5: string, fileName: string) => {
  return defHttp.get({
    url: '/file/checkFile',
    params: { md5, fileName: md5 + fileName },
  });
};
export const getGroupId = () => {
  return defHttp.get({ url: '/file/getGroupId' });
};

/**
 * @description: Upload interface
 */
export function uploadApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: uploadUrl,
      onUploadProgress,
    },
    params,
  );
}
